<?php

namespace App\Http\Middleware;

use App\Enums\ResponseCode;
use Closure;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\App;

class Symstem
{
    /**
     * 如果系统维护会返回429.
     *
     * @return JsonResponse|RedirectResponse|Response
     */
    public function handle(Request $request, Closure $next)
    {
        if (!config('system.soft_status')) {
            $systemDeclaration = App::getLocale() == "en" ? config('system.soft_close_declaration.en') : config('system.soft_close_declaration.zh-CN');
            //判断系统是否正常开放如果没有正常开放就返回httpCode 505错误
            return response()->json([
                'errorMsg' => $systemDeclaration,
            ], ResponseCode::GONE);
        }
        return $next($request);
    }
}
